/**
 * 
 */
package com.javacore;

/**
 * @author Chung
 * @date Jul 28, 2013 9:54:07 PM
 * @projectname Day 6
 * @packagename com.javacore
 * @filename SortByNameDemo.java

 */
public class SortByNameDemo {
	public static void main(String[] args) {
		
		int i, j;
		String temp;
		String name[] = { "Nguyen Dinh Chung", "Do Tien Dung", "Phung Nam Can",
				"Mai Ngoc Thao", "Chu Hoang Son", "Nguyen Huu Dung",
				"Tran Khac Con" };
		String FirstName[] = new String[10] ;
		int b = name.length;
		//System.out.println(b);
		for (i=0;i<name.length;i++)	{
			int a = name[i].lastIndexOf(" ");
			FirstName[i] = name[i].substring(a);
//			System.out.println("Name["+i+"] = "+name[i]);
//			System.out.println();
//			System.out.println("FirstName["+i+"] = "+FirstName[i]);
//			System.out.println();
		}
		
		for (i = 0; i < name.length - 1; i++) {
			for (j = i + 1; j < name.length; j++) {
//				String g = FirstName[j];
//				String h = FirstName[i];
//				System.out.println("FirstName[j]"+g);
//				System.out.println("FirstName[i]"+h);
//				boolean o = FirstName[j].compareTo(FirstName[i]) < 0;
//				System.out.println(o);
//				System.out.println();
				
				// Sap xep ten
				
				if (FirstName[j].compareTo(FirstName[i]) < 0) {
					temp = name[i];
					name[i] = name[j];
					name[j] = temp;
//					System.out.println("FirstName["+i+"] = "+FirstName[i]);
//					System.out.println();
//					System.out.println("Name["+i+"] = "+name[i]);
//					System.out.println();
//					System.out.println("Temp :"+temp);
//					System.out.println();
				}
			}
		}
		
		for (i = 0; i < name.length; i++) {
			System.out.println(name[i]);
		}

		
		
		
	}
}
